package com.app.business.service.newTextForCs;

import com.app.business.model.newTextForCs.TextContract;
import com.app.system.jpa.JpaBaseDao;
import com.app.system.jpa.PageBean;
import com.app.system.jpa.Wrapper;
import com.google.common.collect.Maps;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;
import java.util.List;
import java.util.Map;

/**
 * 测算基础管理
 * Created by ddz on 2020/1/20.
 */
@SuppressWarnings(value = "ALL")
@Service
@Transactional
public class TextContractService extends JpaBaseDao<TextContract, Integer> {

    /**
     * 分页处理
     *
     * @return
     */
    public PageBean<TextContract> getTextContractPageBean() {
        //查询语句
        StringBuffer query = new StringBuffer("c from TextContract c ");

        //默认排序(PageBean指定排序字段类型的话，则默认排序不使用)
        StringBuffer orderBy = new StringBuffer("c.projectCode,c.chooseNum");
        Wrapper wrapper = new Wrapper(query, orderBy);
        wrapper.initSearchParams();

        return this.pageHql(wrapper);
    }


    /**
     * 查询项目名称列表
     *
     * @return
     */
    public List<String> getTextContractProjectNameList(String projectCode) {
        StringBuffer sql = new StringBuffer("select c.project_name from text_contract c where c.project_code =:projectCode group by c.project_name");
        Map<String, Object> map = Maps.newLinkedHashMap();
        map.put("projectCode", projectCode);
        List list = this.findSqlObject(sql.toString(), map);
        return list;
    }

    /**
     * 通过参数配置得到下面所有的面积户型
     *
     * @return
     */
    public List<TextContract> getTextContractListByProjectCode(String projectCode) {
        //查询语句
        StringBuffer hql = new StringBuffer("from TextContract tc where tc.projectCode =:projectCode order by tc.chooseNum");
        Map map = Maps.newHashMap();
        map.put("projectCode", projectCode);
        return this.findHql(hql.toString(), map);
    }
}
